package com.newtouch.bxzs.database.synchronize.batch.process;

import cn.hutool.core.bean.BeanUtil;
import com.newtouch.bxzs.common.base.model.CooperationCompanyOrganization;
import com.newtouch.bxzs.common.base.model.Organization;
import com.newtouch.bxzs.common.base.util.PinYinUtils;
import com.newtouch.bxzs.database.synchronize.model.OrganizationBO;
import org.springframework.batch.item.ItemProcessor;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 机构同步数据处理
 *
 * <p>
 * <b>History:</b>
 * <table border="1">
 * <tr>
 * <th>Date</th>
 * <th>Operator</th>
 * <th>Memo</th>
 * </tr>
 * <tr>
 * <td>2021/1/7 10:55</td>
 * <td>Amour</td>
 * <td>Create</td>
 * </tr>
 * </table>
 *
 * @author yuanjie
 * @version 1.0.0
 * @since 1.0.0
 */
@Component
public class ProcesorOrganization {

    /**
     * 处理本端机构消息
     * @return ItemProcessor
     */
    public ItemProcessor<OrganizationBO, Organization> processorOwnOrgan(){
        return organizationBO -> {
            Organization organization = new Organization();
            BeanUtil.copyProperties(organizationBO,organization);
            organization.setOrganizationNameFullSpelling(PinYinUtils.toPinyin(organizationBO.getOrganizationName()));
            return organization;
        };
    }


    /**
     * 处理对端机构信息
     * @return ItemProcessor
     */
    public ItemProcessor<OrganizationBO, CooperationCompanyOrganization> processorCooperationOrgan(){
        return organizationBO -> {
            //处理数据
            CooperationCompanyOrganization cooperationCompanyOrganization = new CooperationCompanyOrganization();
            cooperationCompanyOrganization.setCooperationCompanyOrganizationCode(organizationBO.getOrganizationCode());
            cooperationCompanyOrganization.setCooperationCompanyOrganizationName(organizationBO.getOrganizationName());
            cooperationCompanyOrganization.setCooperationCompanyOrganizationTelephone(organizationBO.getOrganizationTelephone());
            cooperationCompanyOrganization.setCooperationCompanyOrganizationType(organizationBO.getOrganizationType());
            cooperationCompanyOrganization.setCooperationCompanyOrganizationDescription(organizationBO.getOrganizationDescription());
            cooperationCompanyOrganization.setCooperationCompanyParentOrganizationCode(organizationBO.getParentOrganizationCode());
            cooperationCompanyOrganization.setCreateUserId("admin");
            cooperationCompanyOrganization.setCreateTime(new Date());
            cooperationCompanyOrganization.setUpdateUserId("admin");
            cooperationCompanyOrganization.setUpdateTime(new Date());
            cooperationCompanyOrganization.setEnableFlag(true);
            cooperationCompanyOrganization.setDeleteFlag(false);
            cooperationCompanyOrganization.setCooperationCompanyOrganizationNameFullSpelling(PinYinUtils.toPinyin(organizationBO.getOrganizationName()));
            return cooperationCompanyOrganization;
        };
    }
}
